<?php $this->load->view('header') ?>

<div id="content">
<div class="column full fl">
		
		<div class="box">
		<div class="box-header">History Rekening</div>
		<div class="box-content box-table">
		<div class="clear"></div>
		<br />
		
        	<?php if (isset($errorMessage)) : ?>
            	<div class="notification <?php echo ((isset($isSuccess) && $isSuccess) ? 'success' : 'error');?>"><?php echo $errorMessage; ?></div>
	        <?php endif; ?>    	
	        <br />
	        
	        <table class="tablebox">
	        	<tr class='even'>
	        		<td width='50'><b>Periode</b></td>
	        		<td width='10'> : </td>
	        		<td>
	        			<!-- Tahun -->
	        			<select name='year' id='year' class='modalLoader'>
                        	<option value='all'>Pilih Tahun</option>
                        	<?php for($y=date('Y')-1; $y<=date('Y')+1; $y++):?>
                        	<option value='<?php echo $y?>' <?php echo get_data($uri_to_assoc,'year') == $y ? 'selected="selected"' : '';?>>				                   
	                        	<?php echo $y?>
							</option>
                        	<?php endfor?>
						</select>       
						
						<!-- Bulan -->
						<select name='month' id='month' class='modalLoader'>
                        	<option value='all'>Pilih Bulan</option>
                        	<?php for($m=01; $m<=12; $m++):?>
                        	<?php $month = substr('0'.$m, -2);?>
                        	<option value='<?php echo $month;?>' <?php echo get_data($uri_to_assoc,'month') == $month ? 'selected="selected"' : '';?>>				                   
	                        	<?php echo monthName($m).' ('.$month.')';?>
							</option>
                        	<?php endfor?>
						</select>                      	
					</td>
	        	</tr>
	        	<tr class='even'>
	        		<td width='50'><b>Tipe</b></td>
	        		<td width='10'> : </td>
	        		<td>
	        			<select name='tipe' id='tipe' class='modalLoader'>
                        	<option value='all'>Semua Tipe</option>
                        	<?php if($listRekTipe) foreach($listRekTipe as $tipe=>$list):?>
                        		<optgroup label='<?php echo $tipe?>'></optgroup>
                        		
                        		<?php if($list) foreach($list as $id=>$name):?>
                        			<option value='<?php echo $id?>' <?php echo get_data($uri_to_assoc,'tipe') == $id ? 'selected="selected"' : '';?>>				                   
	                        			<?php echo '&nbsp;&nbsp;&nbsp;'.$name?>
									</option>
                        		<?php endforeach;?>
                        		
                        	<?php endforeach;?>
                        </select>
					</td>
	        	</tr>
	        </table>
	        <br />

            <?php echo $paging?>
            <table class="tablebox">
            <thead class="table-header" style="border-top:1px solid #ccc;border-bottom:1px solid #ccc">
                <tr>
                	<th width="10">No</th>
                	<th width="150">Tipe</th>
                    <th>Nama</th>
                    <th>Realisasi</th>
                    <th>Anggaran</th>
                    <th>Naik/Turun</th>
                    <th>(%)</th>
                    <th width="200">Action</th>
                </tr>
            </thead>
            <tbody>
            <?php $no = get_data($uri_to_assoc,'page')+1;?>
            <?php $totalRealisasi = 0;?>
            <?php $totalAnggaran = 0;?>
            <?php $totalSelisih = 0;?>
            
            <?php if ($dataView) foreach($dataView as $key=>$row) : ?>
                <?php $class = $no % 2 == 0 ? 'even' : 'odd' ?>
                <?php $style = $row['historySelisih'] < 0 ? 'style="color:red;"' : 'style="color:green;"';?>
                
                <tr class=<?php echo $class?> style='font-weight:bold;'>
                	<td><?php echo $no?></td>               
                	
                	<!-- Tipe -->
                	<td>
                	<?php if($key > 0):?>
                		<?php echo $dataView[$key-1]['rekTipeNama'] == $row['rekTipeNama'] ? '' : $row['rekTipeNama'];?>
                	<?php else:?>
                    	<?php echo $row['rekTipeNama'];?>
                    <?php endif;?>
                    </td>
                    
                    <td <?php echo $style?>><?php echo get_data($row,'rekeningNama')?></td>
                    <td <?php echo $style?>>Rp. <span style="float:right;"><?php echo number_format($row['historyRealisasi']);?></span></td>
                    <td <?php echo $style?>>Rp. <span style="float:right;"><?php echo number_format($row['historyAnggaran']);?></span></td>
                    <td <?php echo $style?>>Rp. <span style="float:right;"><?php echo number_format($row['historySelisih']);?></span></td>
                    <td <?php echo $style?>><span style="float:right;"><?php echo number_format($row['historyProsentase']);?> %</span></td>

					<?php $totalRealisasi += $row['historyRealisasi'];?>
					<?php $totalAnggaran += $row['historyRealisasi'];?>
					<?php $totalSelisih += $row['historySelisih'];?>
					
                    <td>
                        <?php echo isAccess('akuntansi','rekrincian','edit') ? anchor('akuntansi/rekHistory/edit/year/'.$uri_to_assoc['year'].'/month/'.$uri_to_assoc['month'].'/tipe/'.$uri_to_assoc['tipe'].'/id/' . $row['rekHistoryId'],'<span class="icon_text edit"></span>Edit', 'class="button white"', 'class="button white"') : ''?>
                        <?php echo isAccess('akuntansi','rekrincian','delete') ? anchor('akuntansi/rekHistory/view/action/delete/year/'.$uri_to_assoc['year'].'/month/'.$uri_to_assoc['month'].'/tipe/'.$uri_to_assoc['tipe'].'/id/' . $row['rekHistoryId'],'<span class="icon_text cancel"></span>Hapus', array('onClick' => "return confirm('".$this->lang->line('global_confirm_delete')."')" , 'class' => "button white")) : ''?>
                    </td>
                </tr>
                <?php $no++?>
            <?php endforeach;?>
            </tbody>
            
            <?php if( $dataView && get_data($uri_to_assoc,'year') != 'all' && get_data($uri_to_assoc,'month') != 'all' && get_data($uri_to_assoc,'tipe') != 'all' ):?>
            <tfoot>
            	<tr class='<?php echo $no % 2 == 0 ? 'even' : 'odd' ?>' style='font-weight:bold;'>
            		<td></td><td></td>
            		<td>Jumlah</td>
            		<td>
            			Rp. <span style="float:right;"><?php echo number_format($totalRealisasi);?>
            		</td>
            		<td>
            			Rp. <span style="float:right;"><?php echo number_format($totalAnggaran);?>
            		</td>
            		<td>
            			Rp. <span style="float:right;"><?php echo number_format($totalSelisih);?>
            		</td>
            		<td></td><td></td>
            	</tr>
	            <tr class='<?php echo ($no+1) % 2 == 0 ? 'even' : 'odd' ?>' style='font-weight:bold;'>
            		<td></td><td></td><td></td><td></td>
            		<td></td><td></td><td></td>
            		<td>
            			<?php echo isAccess ('akuntansi', 'rekhistory', 'exportpdf') ? anchor('akuntansi/rekHistory/exportPdf/year/'.get_data($uri_to_assoc,'year').'/month/'.get_data($uri_to_assoc,'month').'/tipe/'.get_data($uri_to_assoc,'tipe'), '<span class="icon_text pdf"></span>Export Data', 'class="button white"') : '';?>    
            		</td>
	            </tr>
            </tfoot>
            <?php endif;?>
            
            </table>
            <div id="paging">
            <?php echo $paging?>
            </div>
		</div>
		</div>
	
	</div>

<script type="text/javascript">
<!--
jQuery(document).ready(function($){
	formChange = function() {
        if (this.value)
            document.location.href = site_url('akuntansi/rekHistory/view/year/'+ $('#year').val() +'/month/'+ $('#month').val() +'/tipe/'+ $('#tipe').val() );
    };
    $('#year, #month, #tipe').bind('change',formChange);
});
//-->
</script>
<?php $this->load->view('footer') ?>